package com.itheima.zhaohang.threechenge;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by 赵航 on 2017/7/30.
 */

public class MenuAdapter  extends BaseAdapter {
    private List<AreaBeen> mAreaBeens;
    private Context mContext;

    public MenuAdapter(Context context,List<AreaBeen> areaBeens) {
        mAreaBeens = areaBeens;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mAreaBeens==null?0:mAreaBeens.size();
    }

    @Override
    public AreaBeen getItem(int i) {
        return mAreaBeens.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view==null){
            //view = View.inflate(mContext, R.layout.item, null);//容易导致父控件的部分属性失效
            view = LayoutInflater.from(mContext).inflate(R.layout.item, viewGroup, false);
            viewHolder = new ViewHolder();
            viewHolder.mTextView =(TextView) view.findViewById(R.id.text_two);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();

        }
        //赋值
        AreaBeen areaBeen = mAreaBeens.get(i);
        viewHolder.mTextView.setText(areaBeen.name);
if (areaBeen.isSclect){
    viewHolder.mTextView.setBackgroundResource(R.mipmap.choose_item_selected);
}else {
    viewHolder.mTextView.setBackgroundColor(Color.TRANSPARENT);
}

        return view;
    }
    public class  ViewHolder{
        TextView mTextView;
    }
}
